package face.pay.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Auther: zkj
 * @Date: 2019/8/2 17:29
 * @Description:
 */
public class StringValidateUtils {

    public static Boolean isEmail(String str) {
        Boolean isEmail = false;
        String expr = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$";

        if (str.matches(expr)) {
            isEmail = true;
        }
        return isEmail;
    }

    /**
     * 判断是否是手机号
     *
     * @param phone
     * @return
     */
    public static boolean checkPhone(String phone) {
        Pattern pattern = Pattern
                .compile("^(13[0-9]|15[0-9]|153|15[6-9]|180|18[23]|18[5-9])\\d{8}$");
        Matcher matcher = pattern.matcher(phone);

        if (matcher.matches()) {
            return true;
        }
        return false;
    }

    public static Boolean isOk(String rex,String str){
        try{
            Pattern compile = Pattern.compile(rex);
            Matcher matcher = compile.matcher(str);
            if(matcher.matches()) {
                return  true;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return  false;
    }





}
